01 / 01

List time function available in javascript?

  1. 1

    setTimeout(callback, delay)

  2. 2

    clearTimeout(timeoutId)

  3. 3

    setInterval(callback, interval)

  4. 4

    clearInterval(intervalId)

  5. 5

    setImmediate(callback)

Difficulty: 3/10
Topics: Date API, Timers, High‑resolution time

Scenario Questions

0-2 years experience
  1. 1

    How would you get the current timestamp in milliseconds since the epoch inside a Node.js service?

  2. 2

    If you need to run a function exactly five seconds from now, which built‑in timer would you use and how would you cancel it if needed?

  3. 3

    What does Date.now() return and how does it differ from creating a new Date object?

2-5 years experience
  1. 1

    We measure an API call’s duration with Date.now() but sometimes see negative values under load. What could cause that and how would you fix it?

  2. 2

    Design a simple rate‑limiter that allows 100 requests per minute. Which timer functions would you choose and why?

  3. 3

    Explain why setTimeout callbacks can fire later than the requested delay in a busy Node.js event loop.

5-8 years experience
  1. 1

    Design a high‑resolution performance logger for a microservice that needs sub‑millisecond precision. Which time APIs would you combine and what trade‑offs do they have?

  2. 2

    Our distributed system orders events by timestamps, but server clocks drift. How would you redesign time handling to avoid ordering bugs?

  3. 3

    During profiling you notice large gaps in process.hrtime readings during GC pauses. How would you account for that in your metrics?

8+ years experience
  1. 1

    We’re migrating a legacy codebase that uses Date everywhere to a deterministic time abstraction for testing and reproducible builds. What strategy would you propose for abstracting time across the organization?

  2. 2

    Discuss the implications of using setTimeout versus a durable message queue with delayed delivery for tasks that must survive process restarts.

  3. 3

    How would you establish a company‑wide policy for handling time zones, daylight‑saving changes, and monotonic clocks in both backend services and client‑side JavaScript?

Follow-up Questions

  • How would you mock or stub these functions in unit tests?
  • What are the risks of using a wall‑clock timer for measuring elapsed time?
  • Can you give an example where you’d prefer process.hrtime over Date.now?